using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Headspring.Training.Domain.Model;
using Headspring.Training.Domain.Services;
using Headspring.Training.WebUI.Presenters;
using Headspring.Training.WebUI.Views;
using StructureMap;

namespace Headspring.Training.WebUI
{
	public partial class Layout : MasterPage, ILayoutView
	{
		private Employee _currentUser;
		private string _version;

		public Employee CurrentUser
		{
			get { return _currentUser; }
			set { _currentUser = value; }
		}

		protected string Version
		{
			get { return _version; }
		}

		public void AddFlashMessage(FlashMessage message)
		{
			Panel panel = new Panel();
			if(message.Type == FlashMessage.MessageType.Message)
			{
				panel.CssClass = "flash message";
			}
			else if(message.Type == FlashMessage.MessageType.Error)
			{
				panel.CssClass = "flash error";
			}

			panel.Controls.Add(new LiteralControl(message.Message));
			flash.Controls.Add(panel);
		}

		protected void Page_Load(object sender, EventArgs e)
		{
			LayoutPresenter presenter = ObjectFactory.FillDependencies<LayoutPresenter>();
			presenter.Execute(this);

			IApplicationInformation information = ObjectFactory.GetInstance<IApplicationInformation>();
			_version = information.ProductVersion;
		}
	}
}